<?php
/***************************************************************************
 *				   (admin) index.php
 *				  -------------------
 *	 begin		  : Saturday, Feb 13, 2001
 *	 copyright		  : (C) 2001 The phpBB Group
 *	 email		  : support@phpbb.com
 *
 ***************************************************************************/
/***************************************************************************
 *
 *	 This program is free software; you can redistribute it and/or modify
 *	 it under the terms of the GNU General Public License as published by
 *	 the Free Software Foundation; either version 2 of the License, or
 *	 (at your option) any later version.
 *
 ***************************************************************************/
/* Modifications made by CPG Dev Team http://cpgnuke.com		*/
/************************************************************************/
if (!defined('ADMIN_PAGES')) { exit; }

	$template->set_filenames(array('body' => 'admin/forums/index_body'));

	//
	// Get forum statistics
	//
	list($total_posts)  = $db->uFetchRow('SELECT SUM(forum_posts) FROM '.FORUMS_TABLE);
	list($total_topics) = $db->uFetchRow('SELECT SUM(forum_topics) FROM '.FORUMS_TABLE);

	$boarddays = (time() - $board_config['board_startdate']) / 86400;

	$avatar_dir_size = 0;
	if ($avatar_dir = opendir($MAIN_CFG['avatar']['path']))
	{
		while ($file = readdir($avatar_dir)) {
			if ($file != '.' && $file != '..' ) {
				$avatar_dir_size += filesize($MAIN_CFG['avatar']['path'] . '/' . $file);
			}
		}
		closedir($avatar_dir);
		$avatar_dir_size = filesize_to_human($avatar_dir_size);
	}
	else
	{
		// Couldn't open Avatar dir.
		$avatar_dir_size = $lang['Not_available'];
	}

	//
	// DB size ... MySQL only
	//
	// This code is heavily influenced by a similar routine
	// in phpMyAdmin 2.2.0
	//
	if (0 === strpos(SQL_LAYER, 'mysql')) {
		$result = $db->query('SHOW TABLE STATUS');
		$dbsize = 0;
		foreach ($result as $table) {
//			if (in_array($table['Name'], $dbtables)) {
				$dbsize += $table['Data_length'] + $table['Index_length'];
//			}
		}
		$dbsize = filesize_to_human($dbsize);
	} else {
		$dbsize = $lang['Not_available'];
	}

	$template->assign_vars(array(
		'NUMBER_OF_POSTS'  => $total_posts,
		'NUMBER_OF_TOPICS' => $total_topics,
		'START_DATE'       => create_date($board_config['default_dateformat'], $board_config['board_startdate']),
		'POSTS_PER_DAY'    => sprintf('%.2f', min($total_posts,  $total_posts  / $boarddays)),
		'TOPICS_PER_DAY'   => sprintf('%.2f', min($total_topics, $total_topics / $boarddays)),
		'AVATAR_DIR_SIZE'  => $avatar_dir_size,
		'DB_SIZE'          => $dbsize
	));
